package com.health.service.impl;

import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.entity.Disease;
import com.health.entity.InquiryOrder;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryInquiryOrderDTO;
import com.health.mapper.InquiryOrderMapper;
import com.health.service.IInquiryOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 问诊订单 服务实现类
 * </p>
 *
 * @author health
 * @since 2023-04-19
 */
@Service
public class InquiryOrderServiceImpl extends ServiceImpl<InquiryOrderMapper, InquiryOrder> implements IInquiryOrderService {

    @Autowired InquiryOrderMapper mapper;


    //问诊订单分页查询数据
    @Override
    public PageData getPageAll(Integer pageNum, Integer pageSize,QueryInquiryOrderDTO queryInquiryOrderDTO) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (queryWrapper!=null){
            if(!StringUtils.isEmpty(queryInquiryOrderDTO.getTradeNo())){
                queryWrapper.like("trade_no",queryInquiryOrderDTO.getTradeNo());
            }
            if (queryInquiryOrderDTO.getStatus()!=null){
                queryWrapper.eq("status",queryInquiryOrderDTO.getStatus());
            }
            if (queryInquiryOrderDTO.getReplyDate()!=null){
                queryWrapper.gt("reply_date",queryInquiryOrderDTO.getReplyDate());
            }
            if (queryInquiryOrderDTO.getQuestionDate()!=null){
                queryWrapper.lt("question_date",queryInquiryOrderDTO.getQuestionDate());
            }
            if (queryInquiryOrderDTO.getPatientName()!=null){
                queryWrapper.like("patient_name",queryInquiryOrderDTO.getPatientName());
            }
        }
        //创建分页对象
        IPage<InquiryOrder> page = new Page<>(pageNum,pageSize);
        //查询
        IPage ipage =  mapper.selectPage(page,queryWrapper);
        //封装返回
        return new PageData(ipage.getTotal(),ipage.getRecords());
    }
}
